import 'package:color_dart/RgbaColor.dart';
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/components/labels/index.dart';


class Tab extends StatelessWidget {
  final String title;
  final bool active;
  final Function press;

  const Tab({
    Key key,
    @required this.title,
    this.active,
    this.press,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (active) {
      return GestureDetector(
        onTap: press,
        child: Container(
          height: 48,
          padding: EdgeInsets.only(left: 20,top: 15,right: 20),
          child: LabelTitleDetail(
            title: '$title',
          ),
        ),
      );
    }
    return GestureDetector(
      onTap: press,
      child: Container(
        height: 48,
          child: Text('$title',style: TextStyle(color: rgba(136, 135, 135, 1),fontSize: 15),),  padding: EdgeInsets.only(left: 20,top: 15,right: 20)),
    );
  }
}

class TabsBtn extends StatefulWidget {
  final Function onChange;
  final int actIndex;

  const TabsBtn({
    Key key,
    this.onChange,
    this.actIndex,
  }) : super(key: key);

  @override
  _TabsBtnState createState() => _TabsBtnState();
}

class _TabsBtnState extends State<TabsBtn> {
  int activeIndex = 0;

  changeIndex(int index) {
    setState(() {
      activeIndex = index;
    });
    widget.onChange(index);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      color: Colors.white,
      // padding: EdgeInsets.only(top: 8, left: 10, right: 16, bottom: 10),
      child: Row(
        children: [
          Tab(
            title: '主页',
            active: widget.actIndex == 0,
            press: () => changeIndex(0),
          ),
          Tab(
            title: '小组动态',
            active: widget.actIndex == 1,
            press: () => changeIndex(1),
          ),
          Tab(
            title: '内容中心',
            active: widget.actIndex == 2,
            press: () => changeIndex(2),
          ),
        ],
      ),
    );
  }
}
